package com.ricchieri.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.springframework.cache.annotation.Cacheable;

import com.ricchieri.dao.interf.IPassengerTypeDao;
import com.ricchieri.filter.BasicFilter;
import com.ricchieri.model.PassengerType;

public class PassengerTypeDao extends GenericDao implements IPassengerTypeDao {
	private static final long serialVersionUID = 1317011348726169763L;

	@Override
	@Cacheable(value="passengerType")
	@SuppressWarnings("unchecked")
	public List<PassengerType> getAllPassengerTypes(BasicFilter filter) {
		Criteria criteria = criteriaAllPassengerType(filter);
		
		return criteria.list();
	}
	
	private Criteria criteriaAllPassengerType(BasicFilter filter) {
		return super.criteriaAllBasic(filter, PassengerType.class);
	}	
	
	@Override
	protected String getTableName() {
		return "passengerType";
	}

	@Override
	public PassengerType getPassengerTypeById(BasicFilter passengerTypeFilter) {
		Criteria criteria = criteriaAllPassengerType(passengerTypeFilter);
		
		return (PassengerType) criteria.list().get(0);
	}
}
